package com.szcinda.controller;

import com.szcinda.repository.FeeItem;
import com.szcinda.service.PageResult;
import com.szcinda.service.dto.feeItem.FeeItemCreateDto;
import com.szcinda.service.dto.feeItem.FeeItemQueryDto;
import com.szcinda.service.dto.feeItem.FeeItemService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("feeItem")
public class FeeItemController {

    private final FeeItemService feeItemService;

    public FeeItemController(FeeItemService feeItemService) {
        this.feeItemService = feeItemService;
    }

    @PostMapping("create")
    @OperationLogAnnotation(operDesc = "新增费用科目", operModel = "费用科目管理")
    public Result<String> create(@RequestBody FeeItemCreateDto createDto) {
        feeItemService.create(createDto);
        return Result.success();
    }

    @GetMapping("delete/{id}/{userId}")
    @OperationLogAnnotation(operDesc = "删除费用科目", operModel = "费用科目管理")
    public Result<String> delete(@PathVariable String id, @PathVariable String userId) {
        feeItemService.delete(id, userId);
        return Result.success();
    }

    @PostMapping("query")
    public PageResult<FeeItem> query(@RequestBody FeeItemQueryDto queryDto) {
        return feeItemService.query(queryDto);
    }

    @GetMapping("all")
    public Result<List<FeeItem>> all() {
        return Result.success(feeItemService.getAll());
    }
}
